<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');

$adm_functions->is_admin_login();

$icon_description='
<table><tr><td>
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td>
				<img src="show_files/acc_active.png" width="16" height="16" border="0" alt="Pending" />
			</td>
			<td>
				Account is <u>active</u>  |
			</td>
			<td>
				<img src="show_files/acc_inactive.png" width="16" height="16" border="0" alt="Visible" />
			</td>
			<td>
				Account is <u>inactive</u>  |
			</td>
			<td>
				<img src="show_files/acc_susp.png" width="16" height="16" border="0" alt="Pending" />
			</td>
			<td>
				Account is <u>unsuspended</u>  |
			</td>
			<td>
				<img src="show_files/acc_unsusp.png" width="16" height="16" border="0" alt="Visible" />
			</td>
			<td>
				Account is <u>suspended</u>  |
			</td>
			<td>
				<img src="show_files/acc_del.png" width="16" height="16" border="0" alt="Visible" />
			</td>
			<td>
				<u>Delete</u> Account
			</td>
		</tr>
	</table>
</td></tr><tr><td align="center">
	<table cellspacing="0" cellpadding="4" border="0" align="center">
		<tr align="center">
			<td align="center">
				<i>Click on icon to toggle state or execute command.</i>
			</td>
		</tr>
	</table>
</td></tr></table>
';

$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
<tr>
	<td class="menudottedline" width="40%">
		<div class="pathway"><img border="0" src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
	<td class="menudottedline" align="right">
				<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
		<tr valign="middle" align="center">
				<td>&nbsp;</td>
				<td>
					<a class="toolbar" href="admin.php?show=index">
					<img src="show_files/home.png" alt="Home" name="home" title="Home" align="middle" border="0" />				<br />Home</a>
				</td>
					<td>&nbsp;</td>
					<td>
			<a class="toolbar" href="admin.php?show=add_user">
				<img src="show_files/new_f200.png"  alt="New" name="new" title="New" align="middle" border="0" />				<br />New</a>
		</td>
				</tr>
		</table>
			</td>
</tr>
</table>

<br />
';

//$adm_functions->is_admin_login();
//$listdescIcon2=$adm_functions->getActiondesc1('user');
//$qry="select * from general_setting where id=1";
//$res=$dbh->query($qry);
//$row=mysql_fetch_object($res);
//$hargacoin=$row->decrease_bid;

if($action=="do_delete"){
	$dbh->query("delete from anggota where user_id=$id");
	echo '<script>window.location.href="admin.php?show=user_manager";</script>';
}
if($action=="do_active"){
	$dbh->query("update anggota set active='Y' where user_id=$id");
// KIRIM PEMBERITAHUAN KE USER
	$qryactivate="select * from anggota where user_id=$id";
	$selectactivate=$dbh->query($qryactivate);
	while($sqlRow=mysql_fetch_object($selectactivate))
	{
		$username_info=$sqlRow->username;
		$password_info=$sqlRow->password;
		$email_info=$sqlRow->email;
	}
	$subject='New Member Registration';	
	$isi_mail = "Hello, \n
	KINI has approved your registration. You now can now login to the Kini website. \n
	This is your Account Information:
	Username: $username_info
	Password: $password_info \n
	Kind regards, \n
	KINI";
	$admin_email="admin@kinifurniture.com";
								mail($email_info, $subject, $isi_mail,
					 "From: $admin_email\r\n"
					."Reply-To: $admin_email\r\n"
					."X-Mailer: PHP/" . phpversion());

	echo '<script>window.location.href="admin.php?show=user_manager";</script>';
}
if($action=="do_inactive"){
	$dbh->query("update anggota set active='N' where user_id=$id");
	echo '<script>window.location.href="admin.php?show=user_manager";</script>';
}
if($action=="do_suspend"){
	$dbh->query("update anggota set suspend='Y' where user_id=$id");
	echo '<script>window.location.href="admin.php?show=user_manager";</script>';
}
if($action=="do_unsuspend"){
	$dbh->query("update anggota set suspend='N' where user_id=$id");
	echo '<script>window.location.href="admin.php?show=user_manager";</script>';
}
if($action=="") $action="list";

if($action=="list"){

if(!$page_no)
	$page_no=1;
$MAX=10;
$lastrow=$MAX+$page_no;
if(!next_page)
	$next_page=1;
$next_page=$next_page+1;

$imgSr=$page_no;

if(!$sort)
$sort='all';

if($sort=='all')
{
	$condition="";
	$section='All';
	$selected1='selected';
}

if($sort=='inactive')
{
	$condition=" where active='N'";
	$section='Inactive User';
	$selected2='selected';
}

if($sort=='suspended')
{
	$condition=" where suspend='Y'";
	$section='Suspended User';
	$selected3='selected';
}
if ($search) {
	if ($condition=='')
		$condition=" where username like '%$search%'";
	else
		$condition.=" and username like '%$search%'";
}
	$sort_username='	
<select name="sort" class="inputbox" size="1" onchange="document.adminForm.submit();">
                 <option value="all" '.$selected1.'>All</option>
                 <option value="inactive" '.$selected2.'>Inactive User</option>
                 <option value="suspended" '.$selected3.'>Suspended User</option>
                </select>
';
		
//	$User_Name_Dropdown="<select name='username' class='text' id='username'>";
	$qry="select * from anggota $condition order by nama asc";
	$lim_min = ($page_no-1)*$MAX;
	$qry2="$qry limit $lim_min,$MAX"; 
	$select=$dbh->query($qry2);
	$TOTAL_RECORDSET=$dbh->num_rows($dbh->query($qry));

//	$User_Name_Dropdown.="<option value='' selected> Please Select</option>";
	$user_list='';
	$nomor_urut=(($page_no-1)*$MAX);
	while($sqlRow=mysql_fetch_object($select))
	{
	$nomor_urut++;
//		$User_Name_Dropdown.="<option value='$sqlRow->username'>".$sqlRow->username."</option>";
	$user_id=$sqlRow->user_id;
	$username=$sqlRow->username;
	$name=$sqlRow->nama;
	$email=$sqlRow->email;
	$telp=$sqlRow->telp;
	$fax=$sqlRow->fax;
	$perus=$sqlRow->perus;
	if ($sqlRow->active=='Y') 
			$urlactive="<a href='admin.php?show=user_manager&action=do_inactive&id=$user_id'><img border='0' src='show_files/acc_active.png' /></a>";
		else 
			$urlactive="<a href='admin.php?show=user_manager&action=do_active&id=$user_id'><img border='0' src='show_files/acc_inactive.png' /></a>";
	if ($sqlRow->suspend=='Y') 
			$urlsuspend="<a href='admin.php?show=user_manager&action=do_unsuspend&id=$user_id'><img border='0' src='show_files/acc_susp.png' /></a>";
		else 
			$urlsuspend="<a href='admin.php?show=user_manager&action=do_suspend&id=$user_id'><img border='0' src='show_files/acc_unsusp.png' /></a>";
	$user_list.='
		<tr class="row0">
			<td align="center">
				'.$nomor_urut.'
			</td>
			<td align="center">
				<input type="checkbox" id="cb0" name="cid[]" value="10" onclick="isChecked(this.checked);" />				</td>
			<td>
				<a href="'.$SITE_URL.'/admin.php?show=edit_user&id='.$user_id.'" title="Edit Content">'.$username.'</a>
			</td>
			<td>
				'.$name.'
			</td>
			<td align="center">
				'.$urlactive.'
			</td>
			<td align="center">
				'.$urlsuspend.'
			</td>
			<td align="center">
				<a href="admin.php?show=user_manager&action=do_delete&id='.$user_id.'" onclick="return confirm(\'Do you want to delete?\');"><img border="0" src="show_files/acc_del.png" /></a>
			</td>
			<td align="center">
				'.$email.'
			</td>
			<td align="left">
				'.$telp.'
			</td>
			<td align="center">
				'.$fax.'
			</td>
			<td align="left">
				'.$perus.'
			</td>
		</tr>
	';
	}
	$User_Name_Dropdown.="</select>";

	$select=$dbh->query("select user_id from anggota where username='$username'");
	$sqlRow=mysql_fetch_object($select);
	
		
	//pagination settings
//	if(!$page_no) $page_no=0;
//	$start=($page_no * $MAX);
	
////////////////////////////////////////////Pagination////////////////////////////////
//$sql="select * from anggota $condition order by user_id desc";
//$sqlResult=$dbh->query($sql);
//$TOTAL_RECORDSET=$dbh->num_rows();

//$i=1;
//$no_of_pages = ceil($TOTAL_RECORDSET / $MAX);
//if($no_of_pages>1)
//	{
//	$pagination="Go Page :<select name='page_no' onChange='this.form.submit();'>";
//	while($i<=$no_of_pages){ $j=$i-1;
//		$page_no==$j?$pagination.="<option value='$j' selected>$i</option>":$pagination.="<option value='$j'>$i</option>";
//		$i++;
//	}
//	$pagination.="</select>";
//}
//else 
//	$pagination="";
}

//=====================Starting Pagination From Here==========================
	
	//global $my_page_name;
	$my_page_name="./admin.php?show=user_manager&sort=".$sort;
	include("admin_pagination.inc");

?>